In this video we will create an interactive histogram with bluntly and Instagram's are useful in cases
where we want to examine the distribution of values and the one major application and finance is to
analyze the distribution of returns.
So we are still imparted the stocks data frame and with the percentage change method we can create the
returns data frame.
So here we have that daily returns for our six stocks and then we can create a histogram and we can
simply do this with the eye plot method and we pass histogram to the kind parameter.
So let's have a look.
So here we have the interactive histogram with Plumlee and.
For example we can select one single stock for example the Apple stock and TV effort.
That distribution of daily returns.
So for example he and the interval from 0 to 0 point two percent.
We have one hundred fifty six occurrences.
So here we have uh the absolute frequency.
And it's actually no surprise uh that the majority of daily returns is around uh 0 percent here.
But we have also some uh value you see on the tails.
So we have one day where we have minus 10 percent roundabout and even uh one day with a minus twelve
percent.
And we have also quite positive days.
So here returns with 8 percent 9 percent.
And we can also compare this this abuse with another stock for example the Coca-Cola stock so we have
both stocks and that seems like that.
The Apple stock is more volatile.
So there's more risk and the more frequency here in the tails and of course we could simply calculate
the variance or the standard deviation to figure this out but uh we can also see this year graphically.
So this is in many cases more intuitive.
However there is one pitfall when comparing many histogram side distributions and politely and I think
you can hardly see it that politely tries to scale and customize the bits of each distribution separately.
So you might see here that in one apple been there actually two Coca-Cola bins.
So the width of an apple in this actually twice the width of a Coca-Cola bin.
And that makes it hard to compare.
But we can set the bin dimensions for all distributions and we can do this by passing a topper to the
bins parameter.
So we have a bins perimeter and we can pass a topper with three values.
So the first value marks the start.
And let's have a look here on the left hand side so the start might be a maybe a minus 20 percent to
get minus 15 percent to get you all values so we have a minus 15 percent.
Then the second value is for the end and maybe we should to see our 10 percent
and then the third value is actually the width of all bins.
And uh here we could choose maybe uh 0.01 percent per bin
and actually this scale and this dimension applies uh for all of this abuse.
So let's run the site here
and let's again have a look here only at uh the Apple stock and let's add also the Coca-Cola stock and
all with the same bin size that is easier to compare both distributions.
So we can see that the Coca-Cola stock has more frequency here in the middle and on the other hand side
of the Apple stock has more frequency here in the States.
So the Apple stock is obviously more risky than the Coca-Cola stock.
And we can also see on the left hand side our y axis.
And here we have absolute uh quantities of frequencies.
And if we have distributions within a different amount of observations then it might be better to actually
normalize um the y axis.
And uh we can do this with repair meter his norm
and we can either pass probability or percentage.
So first of all let's try a probability
and instead of getting the absolute quantities we get here the relative quantities.
Um in terms of probabilities.
So yes 6 percent 5 percent.
And instead of getting your 0 point 0 6 and 0 point 0 5 you can also get uh the percentage terms low
6 and 5 and we get this by passing a percent instead of probability
and that's roughly the So
and here we have now 6 percent 5 percent and so on.
So this was a short introduction to the plotline histogram and I hope to see also in the next video
by.